﻿@model MyMvc.Model.Models.Article
@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <title>添加附件</title>
    @*--------------------应用easyUI的CSS文件---------------------*@
    <link href="~/themes/css/easyui.css" rel="stylesheet" />
    <link href="~/themes/css/icon.css" rel="stylesheet" />
    <link href="~/themes/css/Site.css" rel="stylesheet" />
    @*---------------------应用easyUI的的JS文件-----------------*@
    <script type="text/javascript" src="~/scripts/jquery-1.8.0.min.js"></script>
    <script type="text/javascript" src="~/scripts/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="~/scripts/easyui-lang-zh_CN.js"></script>

    @*多文档上传*@
    <link href="~/scripts/plupload/jquery.plupload.queue/css/jquery.plupload.queue.css" rel="stylesheet" type="text/css" />
    <script src="~/scripts/plupload/plupload.js"></script>
    <script src="~/scripts/plupload/plupload.flash.js"></script>
    <script src="~/scripts/plupload/jquery.plupload.queue/jquery.plupload.queue.js"></script>
    <script type="text/javascript" src="~/scripts/plupload/zh-cn.js"></script>
    <script type="text/javascript">
        function AfterAdd(data) {
            if (data == "OK") {
                //调用父容器的一个方法，关闭对话框
                window.parent.AfterSetAdd();
            }
            else {
                alert("出错了，请您检查");
            }
        }
    </script>
    <script>
        //plupload事件
        $(document).ready(function () {
            $("#Uploader").pluploadQueue({
                runtimes: 'html5,silverlight,flash,html4',
                url: '@Url.Action("Upload", "Literature", new { infoid = @Model.ID })',
                max_file_size: '4mb',
                chunk_size: '2mb',
                //multipart: false,
                unique_names: false,
                // Resize office on clientside if we can
                resize: { width: 800, height: 600, quality: 90 },
                // Specify what files to browse for
                filters: [{ title: "文件", extensions: "doc,docx,xls,xlsx,ppt,pptx" }],
                flash_swf_url: '../../scripts/plupload/plupload.flash.swf',
                silverlight_xap_url: '../../scripts/plupload/plupload.silverlight.xap',
                multiple_queues: true
            });
            $('#Uploader').bind('Init', function (up, params) {
                $('#Uploader').html("<div>Current runtime: " + params.runtime + "</div>");
            });

            $('#Uploader').click(function (e) {
                uploader.start();
                e.preventDefault();
            });

            $('#Uploader').init();
            // get uploader instance
            var uploader = $("#Uploader").pluploadQueue();

            uploader.bind("FileUploaded", function (upload, file, response) {
                // 从列表中移除文件
                upload.removeFile(file);

                // Response.response returns server output from onUploadCompleted
                // our code returns the url to the image so we can display it
                var imageUrl = response.response;

                $("<img>").attr({ src: imageUrl })
                            .click(function () {
                                $("#ImageView").attr("src", imageUrl);
                                setTimeout(function () {
                                    $("#ImagePreview").modalDialog()
                                                    .closable()
                                                    .draggable();
                                    $("#_ModalOverlay").click(function () {
                                        $("#ImagePreview").modalDialog("hide");
                                    });
                                }, 200);
                            })
                            .appendTo($("#ImageContainer"));
            });

            uploader.bind("Error", function (upload, error) {
                showStatus(error.message, 3000, true);
            });

            uploader.bind("FilesAdded", function (up, filesToBeAdded) {
                if (up.files.length > 5) {
                    up.files.splice(4, up.files.length - 5);
                    showStatus("Only 5 files max are allowed per upload. Extra files removed.", 3000, true);
                    return false;
                }
                return true;
            });

        });
    </script>
</head>
<body>
    <h3>您正在为文章：<font color="red" size="5">@Model.Title</font>添加附件：</h3>
    <fieldset>
        @using (Ajax.BeginForm("FileAdd", "Literature", new AjaxOptions() { OnSuccess = "AfterAdd" }, new { id = "frmadd" }))
        {
            //存放一个隐藏域用来给前台传递ID
            <input type="hidden" name="hidUserId" id="hidUserId" value="@Model.ID" />
            <div id="Uploader">
            </div>
        }
    </fieldset>

</body>
</html>
